package com.itheima.smspringboot.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.smspringboot.common.Result;

import com.itheima.smspringboot.entity.Student;
import com.itheima.smspringboot.service.StudentService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Resource
    private StudentService studentService;



    @PostMapping("/add")
    public Result add(@RequestBody Student student) {
        studentService.add(student);
        return Result.success();
    }
//
    @PutMapping("/update")
    public Result update(@RequestBody Student student) {
        studentService.updateById(student);
        return Result.success();
    }
//
    @DeleteMapping("/delete/{stuId}")
    public Result delete(@PathVariable Integer stuId) {
        studentService.deleteById(stuId);
        return Result.success();

    }
//
    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Student> studentList) {
        studentService.deleteBatch(studentList);
        return Result.success();

    }



    @GetMapping("/selectAll")
    public Result selectAll(Student student) {
        List<Student> studentList = studentService.selectAll(student);
        return Result.success(studentList);
    }


    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize,
                             Student student){
        PageInfo pageInfo = studentService.selectPage(pageNum, pageSize,student);
        return Result.success(pageInfo);

    }




}
